package com.bosssoft.boss_exam_core.common.config;

import com.alibaba.druid.support.http.WebStatFilter;
import com.bosssoft.boss_exam_core.common.Filter.VerifyTokenFilter;
import com.bosssoft.boss_exam_core.common.config.security.AdminJwtTokenHelper;
import com.bosssoft.boss_exam_core.common.token.UserTokenRedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class SysCoreConfig {

    @Bean
    public FilterRegistrationBean filterRegistrationBean2() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new WebStatFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
        filterRegistrationBean.addInitParameter("profileEnable", "true");
        filterRegistrationBean.setOrder(Integer.MAX_VALUE-2);
        return filterRegistrationBean;
    }

    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/3/13
     * @Description 中间人攻击处理的防止过滤器
     * @Param []
     * @Return org.springframework.boot.web.servlet.FilterRegistrationBean
     * @Exception //TODO
     * @since JDK 1.8
     **/
//    @Bean
//    public FilterRegistrationBean filterRegistrationBean1() {
//        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
//        registrationBean.setFilter(new MyXSSFilter());
//        List<String> urlPatterns = new ArrayList<String>();
//        urlPatterns.add("/*");
//        registrationBean.setUrlPatterns(urlPatterns);
//        registrationBean.setOrder(Integer.MAX_VALUE-1);
//        return registrationBean;
//    }

    @Autowired
    private AdminJwtTokenHelper jwtTokenHelper;
    @Bean
    public FilterRegistrationBean filterRegistrationBean3() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new VerifyTokenFilter(jwtTokenHelper));
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/*");
        registrationBean.setUrlPatterns(urlPatterns);
        registrationBean.setOrder(Integer.MAX_VALUE-2);
        return registrationBean;
    }


    @Bean
    public UserTokenRedisManager userTokenRedisManager(){
        UserTokenRedisManager userTokenRedisManager = new UserTokenRedisManager();
        return userTokenRedisManager;
    }
}

